package com.xzp.yygh.hosp.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xzp.yygh.common.exception.YyghException;
import com.xzp.yygh.common.result.ResultCodeEnum;
import com.xzp.yygh.hosp.mapper.ScheduleMapper;
import com.xzp.yygh.hosp.repository.ScheduleRepository;
import com.xzp.yygh.hosp.service.DepartmentService;
import com.xzp.yygh.hosp.service.HospitalService;
import com.xzp.yygh.hosp.service.ScheduleService;
import com.xzp.yygh.model.hosp.BookingRule;
import com.xzp.yygh.model.hosp.Department;
import com.xzp.yygh.model.hosp.Hospital;
import com.xzp.yygh.model.hosp.Schedule;
import com.xzp.yygh.vo.hosp.BookingScheduleRuleVo;
import com.xzp.yygh.vo.hosp.ScheduleOrderVo;
import com.xzp.yygh.vo.hosp.ScheduleQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements ScheduleService {

    @Autowired
    private ScheduleRepository scheduleRepository;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;


    @Override
    public void save(Map<String, Object> paramMap) {
        Schedule schedule = JSONObject.parseObject(JSONObject.toJSONString(paramMap), Schedule.class);
        Schedule targetSchedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(schedule.getHoscode(), schedule.getHosScheduleId());
        if(null != targetSchedule) {
            // 更新schedule
            BeanUtils.copyProperties(schedule, targetSchedule, Schedule.class);
            scheduleRepository.save(targetSchedule);
        } else {
            // 插入schedule
            schedule.setCreateTime(new Date());
            schedule.setUpdateTime(new Date());
            schedule.setIsDeleted(0);
            scheduleRepository.save(schedule);
        }
    }

    @Override
    public Page<Schedule> selectPage(Integer page, Integer limit, ScheduleQueryVo scheduleQueryVo) {

        Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
        //0为第一页
        Pageable pageable = PageRequest.of(page-1, limit, sort);

        Schedule schedule = new Schedule();
        BeanUtils.copyProperties(scheduleQueryVo, schedule);
        schedule.setIsDeleted(0);

        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) //改变默认字符串匹配方式：模糊查询
                .withIgnoreCase(true); //改变默认大小写忽略方式：忽略大小写

        //创建实例
        Example<Schedule> example = Example.of(schedule, matcher);
        Page<Schedule> pages = scheduleRepository.findAll(example, pageable);
        return pages;
    }


    /**
     * 删除指定id和hoscode的schedule
     * @param hoscode
     * @param hosScheduleId
     */
    @Override
    public void remove(String hoscode, String hosScheduleId) {
        Schedule schedule = scheduleRepository.getScheduleByHoscodeAndHosScheduleId(hoscode, hosScheduleId);
        if(null != schedule) {
            scheduleRepository.deleteById(schedule.getId());
        }
    }

    @Override
    public Map<String, Object> getRuleSchedule(long page, long limit, String hoscode, String depcode) {
        // 根据hoscode和deptcode筛选数据
        Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode);
        Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria),
                // 根据日期分类，并取每个类中第一个元素的时间
                Aggregation.group("workDate").first("workDate").as("workDate")
                        // 排班总数
                        .count().as("docCount")
                        // 已预定数
                        .sum("reservedNumber").as("reservedNumber")
                        // 可用数
                        .sum("availableNumber").as("availableNumber"),
                // 按时间降序排列
                Aggregation.sort(Sort.Direction.DESC, "workDate"),
                // 分页操作
                Aggregation.skip((page - 1) * limit),
                Aggregation.limit(limit));
        // 从Schedule对应的表去查找分页信息
        AggregationResults<BookingScheduleRuleVo> bookingScheduleRuleVos = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
        // 获取具体页面信息
        List<BookingScheduleRuleVo> bookingScheduleRuleVoList = bookingScheduleRuleVos.getMappedResults();
        // 获取分类数
        Aggregation totalAgg = Aggregation.newAggregation(Aggregation.match(criteria), Aggregation.group("workDate"));
        AggregationResults<BookingScheduleRuleVo> totalAggResults  = mongoTemplate.aggregate(totalAgg, Schedule.class, BookingScheduleRuleVo.class);
        int total = totalAggResults.getMappedResults().size();
        // 将日期换为星期
        for(BookingScheduleRuleVo bookingScheduleRuleVo: bookingScheduleRuleVoList){
            Date workDate = bookingScheduleRuleVo.getWorkDate();
            String dayOfWeek = this.getDayOfWeek(new DateTime(workDate));
            bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
        }
        // 创建map返回
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("bookingScheduleRuleList", bookingScheduleRuleVoList);
        resultMap.put("total", total);
        // 获取医院的名称
        String hospName = hospitalService.getHospName(hoscode);
        HashMap<String, String> baseMap = new HashMap<>();
        baseMap.put("hosName", hospName);
        resultMap.put("baseMap", baseMap);
        return resultMap;
    }


    /**
     * 根据hoscode和workDate获取Schedule
     * @param hoscode
     * @param depcode
     * @param toDate
     * @return
     */
    @Override
    public List<Schedule> findScheduleByHoscodeAndDepcodeAndWorkDate(String hoscode, String depcode, String toDate) {
        // 根据时间，hoscode， depcode查询数据库， 注意要先将String转时间戳(DateTime)再转具体日期(Date)
        System.out.println(new DateTime(toDate).toDate().toString());
        List<Schedule> scheduleList = scheduleRepository.getScheduleByHoscodeAndDepcodeAndWorkDate(hoscode, depcode, new DateTime(toDate).toDate());
        scheduleList.stream().forEach(item-> {
            this.packSchedule(item);
        });
        return scheduleList;
    }

    @Override
    public Map<String, Object> getBookingScheduleRule(int page, int limit, String hoscode, String depcode) {
        Map<String, Object> result = new HashMap<>();

        //获取预约规则
        Hospital hospital = hospitalService.getByHoscode(hoscode);
        if(null == hospital) {
            throw new YyghException(ResultCodeEnum.DATA_ERROR);
        }
        BookingRule bookingRule = hospital.getBookingRule();

        //获取可预约日期分页数据
        IPage iPage = this.getListDate(page, limit, bookingRule);
        //当前页可预约日期
        List<Date> dateList = iPage.getRecords();
        System.out.println(dateList.toString());
        //获取可预约日期科室剩余预约数
        Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode).and("workDate").in(dateList);
        Aggregation agg = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("workDate")//分组字段
                        .first("workDate").as("workDate")
                        .count().as("docCount")
                        .sum("availableNumber").as("availableNumber")
                        .sum("reservedNumber").as("reservedNumber")
        );
        AggregationResults<BookingScheduleRuleVo> aggregationResults = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
        List<BookingScheduleRuleVo> scheduleVoList = aggregationResults.getMappedResults();
        //获取科室剩余预约数

        //合并数据 将统计数据ScheduleVo根据“安排日期”合并到BookingRuleVo
        Map<Date, BookingScheduleRuleVo> scheduleVoMap = new HashMap<>();
        if(!CollectionUtils.isEmpty(scheduleVoList)) {
            scheduleVoMap = scheduleVoList.stream().collect(Collectors.toMap(BookingScheduleRuleVo::getWorkDate, BookingScheduleRuleVo -> BookingScheduleRuleVo));
        }
        //获取可预约排班规则
        List<BookingScheduleRuleVo> bookingScheduleRuleVoList = new ArrayList<>();
        for(int i=0, len=dateList.size(); i<len; i++) {
            Date date = dateList.get(i);

            BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date);
            if(null == bookingScheduleRuleVo) { // 说明当天没有排班医生
                bookingScheduleRuleVo = new BookingScheduleRuleVo();
                //就诊医生人数
                bookingScheduleRuleVo.setDocCount(0);
                //科室剩余预约数  -1表示无号
                bookingScheduleRuleVo.setAvailableNumber(-1);
            }
            bookingScheduleRuleVo.setWorkDate(date);
            bookingScheduleRuleVo.setWorkDateMd(date);
            //计算当前预约日期为周几
            String dayOfWeek = this.getDayOfWeek(new DateTime(date));
            bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);

            //最后一页最后一条记录为即将预约   状态 0：正常 1：即将放号 -1：当天已停止挂号
            if(i == len-1 && page == iPage.getPages()) {
                bookingScheduleRuleVo.setStatus(1);
            } else {
                bookingScheduleRuleVo.setStatus(0);
            }
            //当天预约如果过了停号时间， 不能预约
            if(i == 0 && page == 1) {
                DateTime stopTime = this.getDateTime(new Date(), bookingRule.getStopTime());
                if(stopTime.isBeforeNow()) {
                    //停止预约
                    bookingScheduleRuleVo.setStatus(-1);
                }
            }
            bookingScheduleRuleVoList.add(bookingScheduleRuleVo);
        }

        //可预约日期规则数据
        result.put("bookingScheduleList", bookingScheduleRuleVoList);
        result.put("total", iPage.getTotal());
        //其他基础数据
        Map<String, String> baseMap = new HashMap<>();
        //医院名称
        baseMap.put("hosname", hospitalService.getHospName(hoscode));
        //科室
        Department department = departmentService.getDepartment(hoscode, depcode);
        //大科室名称
        baseMap.put("bigname", department.getBigname());
        //科室名称
        baseMap.put("depname", department.getDepname());
//月
        baseMap.put("workDateString", new DateTime().toString("yyyy年MM月"));
//放号时间
        baseMap.put("releaseTime", bookingRule.getReleaseTime());
//停号时间
        baseMap.put("stopTime", bookingRule.getStopTime());
        result.put("baseMap", baseMap);
        return result;
    }



    @Override
    public Schedule getById(String scheduleId) {
        Schedule schedule = scheduleRepository.findById(scheduleId).get();
        System.out.println(schedule);
        this.packSchedule(schedule);
        return schedule;
    }


    /**
     * 在医院数据库中查询，填充订单信息ScheduleOrderVo
     * @param scheduleId
     * @return
     */
    @Override
    public ScheduleOrderVo getScheduleOrderVo(String scheduleId) {
        ScheduleOrderVo scheduleOrderVo = new ScheduleOrderVo();
        // 从mongodb中获取schedule
        Schedule schedule = this.getById(scheduleId);
//        Schedule schedule = baseMapper.selectById(scheduleId);
        if(null == schedule) {
            throw new YyghException(ResultCodeEnum.PARAM_ERROR);
        }
        String hoscode = schedule.getHoscode();
        // 获取hospital
        Hospital hospital = hospitalService.getByHoscode(hoscode);
        if(null == hospital) {
            throw new YyghException(ResultCodeEnum.DATA_ERROR);
        }
        // 获取bookingRule
        BookingRule bookingRule = hospital.getBookingRule();
        if(null == bookingRule) {
            throw new YyghException(ResultCodeEnum.PARAM_ERROR);
        }
        // 填充数据
        scheduleOrderVo.setHoscode(schedule.getHoscode());
        scheduleOrderVo.setHosname(hospitalService.getHospName(schedule.getHoscode()));
        scheduleOrderVo.setDepcode(schedule.getDepcode());
        scheduleOrderVo.setDepname(departmentService.getDeptName(schedule.getHoscode(), schedule.getDepcode()));
        scheduleOrderVo.setHosScheduleId(schedule.getHosScheduleId());
        scheduleOrderVo.setAvailableNumber(schedule.getAvailableNumber());
        scheduleOrderVo.setTitle(schedule.getTitle());
        scheduleOrderVo.setReserveDate(schedule.getWorkDate());
        scheduleOrderVo.setReserveTime(schedule.getWorkTime());
        scheduleOrderVo.setAmount(schedule.getAmount());

        //退号截止天数（如：就诊前一天为-1，当天为0）
        int quitDay = bookingRule.getQuitDay();
        // 计算退号当天日期将其与退号时刻拼接得到 退号具体时间
        DateTime quitTime = this.getDateTime(new DateTime(schedule.getWorkDate()).plusDays(quitDay).toDate(), bookingRule.getQuitTime());
        scheduleOrderVo.setQuitTime(quitTime.toDate());

        //预约开始时间
        DateTime startTime = this.getDateTime(new Date(), bookingRule.getReleaseTime());
        scheduleOrderVo.setStartTime(startTime.toDate());

        //预约截止时间
        DateTime endTime = this.getDateTime(new DateTime().plusDays(bookingRule.getCycle()).toDate(), bookingRule.getStopTime());
        scheduleOrderVo.setEndTime(endTime.toDate());

        //当天停止挂号时间
        DateTime stopTime = this.getDateTime(new Date(), bookingRule.getStopTime());
        scheduleOrderVo.setStartTime(startTime.toDate());
        scheduleOrderVo.setStopTime(stopTime.toDate());
        return scheduleOrderVo;
    }



    /**
     * 获取可预约日期分页数据
     */
    private IPage<Date> getListDate(int page, int limit, BookingRule bookingRule) {
//当天放号时间
        DateTime releaseTime = this.getDateTime(new Date(), bookingRule.getReleaseTime());
//预约周期
        int cycle = bookingRule.getCycle();
//如果当天放号时间已过，则预约周期后一天为即将放号时间，周期加1
        if(releaseTime.isBeforeNow()) cycle += 1;
//可预约所有日期，最后一天显示即将放号倒计时
        List<Date> dateList = new ArrayList<>();
        for (int i = 0; i < cycle; i++) {
//计算当前预约日期
            DateTime curDateTime = new DateTime().plusDays(i);
            String dateString = curDateTime.toString("yyyy-MM-dd");
            dateList.add(new DateTime(dateString).toDate());
        }
//日期分页，由于预约周期不一样，页面一排最多显示7天数据，多了就要分页显示
        List<Date> pageDateList = new ArrayList<>();
        int start = (page-1)*limit;
        int end = (page-1)*limit+limit;
        if(end >dateList.size()) end = dateList.size();
        for (int i = start; i < end; i++) {
            pageDateList.add(dateList.get(i));
        }
        IPage<Date> iPage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page(page, 7, dateList.size());
        iPage.setRecords(pageDateList);
        return iPage;
    }



    /**
     * 将Date日期（yyyy-MM-dd HH:mm）转换为DateTime
     */
    private DateTime getDateTime(Date date, String timeString) {
        String dateTimeString = new DateTime(date).toString("yyyy-MM-dd") + " "+ timeString;
        DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").parseDateTime(dateTimeString);
        return dateTime;
    }


    /**
     * 根据schedule向其中的param注入hosName, depName, dayOfWeek
     * @param item
     */
    private void packSchedule(Schedule item) {
        // 获取医院名称
        String hospName = hospitalService.getHospName(item.getHoscode());
        // 获取科室名称
        String deptName = departmentService.getDeptName(item.getHoscode(), item.getDepcode());
        // 获取日期信息
        String dayOfWeek = this.getDayOfWeek(new DateTime(item.getWorkDate()));
        item.getParam().put("hosName", hospName);
        item.getParam().put("depName", deptName);
        item.getParam().put("dayOfWeek", dayOfWeek);
    }

    /**
     * 根据日期获取周几数据
     * @param dateTime
     * @return
     */
    private String getDayOfWeek(DateTime dateTime) {
        String dayOfWeek = "";
        switch (dateTime.getDayOfWeek()) {
            case DateTimeConstants.SUNDAY:
                dayOfWeek = "周日";
                break;
            case DateTimeConstants.MONDAY:
                dayOfWeek = "周一";
                break;
            case DateTimeConstants.TUESDAY:
                dayOfWeek = "周二";
                break;
            case DateTimeConstants.WEDNESDAY:
                dayOfWeek = "周三";
                break;
            case DateTimeConstants.THURSDAY:
                dayOfWeek = "周四";
                break;
            case DateTimeConstants.FRIDAY:
                dayOfWeek = "周五";
                break;
            case DateTimeConstants.SATURDAY:
                dayOfWeek = "周六";
            default:
                break;
        }
        return dayOfWeek;
    }


    /**
     * 更新mongodb， 用于mq 预约挂号
     * @param schedule
     */
    @Override
    public void update(Schedule schedule){
        schedule.setUpdateTime(new Date());
        scheduleRepository.save(schedule);
    }


//    // 获取预定规则
//    @Override
//    public Map<String, Object> getBookingScheduleRule(int page, int limit, String hoscode, String depcode) {
//        HashMap<String, Object> result = new HashMap<>();
//        // 获取预约规则
//        Hospital hospital = hospitalService.getByHoscode(hoscode);
//        if(hospital == null){
//            throw new YyghException(ResultCodeEnum.DATA_ERROR);
//        }
//        BookingRule bookingRule = hospital.getBookingRule();
//        // 获取可预约日期的分页数据
//        IPage iPage = this.getListDate(page, limit, bookingRule);
//        // 条件查询mongodb
//        List<Date> dateList  = iPage.getRecords();
//        System.out.println("dateList: "+ dateList.toString());
//        Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode).and("workDate").in(dateList);
////         分类 聚合数据
//        Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), Aggregation.group("workDate").first("workDate").as("workDate")
//                .count().as("docCount")
//                .sum("reservedNumber").as("reservedNumber")
//                .sum("availableNumber").as("availableNumber"));
//        AggregationResults<BookingScheduleRuleVo> aggregateResult = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
//        List<BookingScheduleRuleVo> scheduleVoList  = aggregateResult.getMappedResults();
//        System.out.println("scheduleVoList: "+scheduleVoList.toString());
//        // 将scheduleVoList变成一个Map对象。 key是workDate, value是BookingScheduleRuleVo对象。
//        //合并数据 将统计数据ScheduleVo根据“安排日期”合并到BookingRuleVo
//        Map<Date, BookingScheduleRuleVo> scheduleVoMap = new HashMap<>();
//
//
//        // 将List转为Map<Date, BookingScheduleRuleVo>
//        if(!CollectionUtils.isEmpty(scheduleVoList)){
//            scheduleVoMap = scheduleVoList.stream().collect(Collectors.toMap(BookingScheduleRuleVo::getWorkDate,
//                    BookingScheduleRuleVo -> BookingScheduleRuleVo));
//        }
//        System.out.println("scheduleVoMap"+scheduleVoMap.toString());
//        System.out.println("keys:"+scheduleVoMap.keySet().toString());
//        // 根据数字字典补充BookingScheduleRuleVo的详细信息
//        ArrayList<BookingScheduleRuleVo> bookingScheduleRuleVoList = new ArrayList<>();
//        for(Date date: dateList){
//            // bookingScheduleRuleVo里面经过聚合操作原本已经有值了
//            BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date);
//            if(bookingScheduleRuleVo == null){
//                bookingScheduleRuleVo = new BookingScheduleRuleVo();
//                // -1表示无号
//                bookingScheduleRuleVo.setAvailableNumber(-1);
//                // 医生数量0
//                bookingScheduleRuleVo.setDocCount(0);
//            }
//            bookingScheduleRuleVo.setWorkDate(date);
//            bookingScheduleRuleVo.setWorkDateMd(date);
//            bookingScheduleRuleVo.setDayOfWeek(this.getDayOfWeek(new DateTime(date)));
//            // 设置最后一天为即将放号,  状态 1) 0：正常 2) 1：即将放号 3) -1：当天已停止挂号
//            // page == iPage.getPages()表示最后一页
//            if(bookingScheduleRuleVo == scheduleVoMap.get(dateList.get(dateList.size()-1)) && page == iPage.getPages()){
//                bookingScheduleRuleVo.setStatus(1);
//            }else{
//                bookingScheduleRuleVo.setStatus(0);
//            }
//            // 第一天过了截至时间就设置状态为停止放号
//            if(bookingScheduleRuleVo == scheduleVoMap.get(dateList.get(0)) && page == 1) {
//                DateTime stopTime = getDateTime(new Date(), bookingRule.getStopTime());
//                if(stopTime.isBeforeNow()){
//                    bookingScheduleRuleVo.setStatus(-1);
//                }
//            }
//            // 将bookingScheduleRuleVo添加到bookingScheduleRuleVoList中
//            bookingScheduleRuleVoList.add(bookingScheduleRuleVo);
//        }
//        //可预约日期规则数据
//        result.put("bookingScheduleList", bookingScheduleRuleVoList);
//        result.put("total", iPage.getTotal());
//        //其他基础数据
//        Map<String, String> baseMap = new HashMap<>();
//        //医院名称
//        baseMap.put("hosname", hospitalService.getHospName(hoscode));
//        //科室
//        Department department = departmentService.getDepartment(hoscode, depcode);
//        //大科室名称
//        baseMap.put("bigname", department.getBigname());
//        //科室名称
//        baseMap.put("depname", department.getDepname());
//        //月
//        baseMap.put("workDateString", new DateTime().toString("yyyy年MM月"));
//        //放号时间
//        baseMap.put("releaseTime", bookingRule.getReleaseTime());
//        //停号时间
//        baseMap.put("stopTime", bookingRule.getStopTime());
//        result.put("baseMap", baseMap);
//        return result;
//
//
//    }


    //    private IPage getListDate(int page, int limit, BookingRule bookingRule) {
//        String releaseTime = bookingRule.getReleaseTime();
//        // 获取发号时间
//        DateTime dateTime = getDateTime(new Date(), releaseTime);
//        // 超过预约截止时间, 预约周期+1
//        String stopTime = bookingRule.getStopTime();
//        DateTime stopDateTime = getDateTime(new Date(), stopTime);
//        // 获取预约周期
//        Integer cycle = bookingRule.getCycle();
//        if(stopDateTime.isBeforeNow()){
//            cycle += 1;
//        }
//        // 获取预约时间区间
//        ArrayList<Date> OrderDateList = new ArrayList<>();
//        for(int i = 0; i< cycle; i++){
//            DateTime currentDate = new DateTime().plusDays(i);
////            OrderDateList.add(currentDate.toDate());
//            String s = currentDate.toString("yyyy-MM-dd");
//            OrderDateList.add(new DateTime(s).toDate());
//        }
//        // 获取页面数据
//        ArrayList<Date> pageList = new ArrayList<>();
//        int start = (page-1)*limit;
//        int end = (page-1)*limit + limit;
//        // 如果总记录数小于7
//        if(OrderDateList.size() < end){
//            end = OrderDateList.size();
//        }
//        // 注入页面数据
//        for(int i=start; i<end; i++){
//            pageList.add(OrderDateList.get(i));
//        }
//        // 返回页面
//        IPage<Date> iPage = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page, limit, OrderDateList.size());
//        iPage.setRecords(pageList);
//        return iPage;
//    }




}
